const express = require("express");
const path = require("path");
const bodypaser = require("body-parser");

const app = express();

require("./model/connect");
// require("./model/user");

app.use(bodypaser.json());
app.use(
  bodypaser.urlencoded({
    extended: false,
  })
);

app.set("views", path.join(__dirname, "views"));
app.set("view engine", "art");
app.engine("art", require("express-art-template"));

app.use(express.static(path.join(__dirname, "public")));
const admin = require("./route/admin");
const home = require("./route/home");

app.all("*", (req, res, next) => {
  res.header("Access-Control-Allow-Credentials", true);
  res.header(
    "Access-Control-Allow-Headers",
    "Power-By,Content-Type,X-Requested-With,X-Version,X-YFG-TOKEN"
  );
  //允许访问的方式
  res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
  //允许所有来源访问(解决跨域的问题)
  res.header("Access-Control-Allow-Origin", "*");
  // 将控制权转到下一个中间件(移交控制权)
  next();
});

app.use("/home", home);
app.use("/admin", admin);

app.listen(9090, () => {
  console.log(`ring...`);
});
